/**
 * 评价
 * @author Qasim <15750783791@163.com>
 * @version 2016/11/1 1.0
 */
document.addEventListener('plusready' , ready , false);

var self = memberInfo = '';
function ready(){
	self = plus.webview.currentWebview();
	memberInfo = plus.storage.getItem('memberInfo');
	memberInfo = $.parseJSON(memberInfo);
	//评价
	$('.add_comment').on('click' , function(){  
		var content = $('.content').val(),level = $('.mui-lvs').length;
		if(!content.trim()){
			toast('请输入内容');return;
		}
		$.ajax({
			type:"post",
			url:apiRoot +'/Home/Comments/addComment/',
			data : {
				bookid : self.aid,
				uid : memberInfo.aid,
				level : level,
				parent_id : 0,
				content : content
			},
			beforeSend:function(){
				plus.nativeUI.showWaiting('提交中...');
			},
			complete:function(){
				plus.nativeUI.closeWaiting();
			},
			success : function(data){
				if(data > 0){
					$('.content').val('');
					$('.manyi map').removeClass('mui-lvs').eq(0).addClass('mui-lvs');
					toast('评价成功');
					mui.fire(plus.webview.getWebviewById(self.pages) , 'addComment' , {})
					setTimeout(function(){
						self.close();
					} , 1000);
				}else{
					toast('评价失败 你已评价过该书籍');
				}
			},
			error : function(e){
				errorPrompt(e);
			}
		});
	})
	
}


